package jdbc2;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/*
* 执行SELECT语句
* */
public class JDBCDemo5 {
    public static void main(String[] args) {
        try(Connection conn = DBUtil.getConnection()){
            Statement stmt = conn.createStatement();
            /*
            * 查询userinfo表中的数据
            * SELECT id,username,password,nickname,age FROM userinfo;
            * */
            String sql = "SELECT id,username,password,nickname,age FROM userinfo;";
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()){
                int id = rs.getInt("id");
                String username = rs.getString("username");
                String password = rs.getString("password");
                String nickname = rs.getString("nickname");
                int age = rs.getInt("age");
                System.out.println(id + " " + username + " " + password + " " +nickname +
                        " " + age);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
